package com.happymmall.dao.impl;

import com.happymmall.dao.BaseDao;
import com.happymmall.dao.ShippingDao;
import com.happymmall.entity.Shipping;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ShippingDaoImpl implements ShippingDao {
    @Override
    public int addShipping(Connection connection, Shipping shipping) throws SQLException {
        PreparedStatement pstm = null;
        ResultSet rs = null;
        int result = 0;

        if (connection != null) {
            shipping.setCreateTime(new java.sql.Timestamp(System.currentTimeMillis())); // 调用 set 方法设置“创建时间”为当前时间
            shipping.setUpdateTime(new java.sql.Timestamp(System.currentTimeMillis())); // 调用 set 方法设置“更新时间”为当前时间
            String sql = "insert into mmall_shipping(user_id,receiver_name, receiver_phone, receiver_mobile, receiver_province, receiver_city, receiver_address, receiver_zip,create_time, update_time) values(?, ?, ?, ?, ?, ?, ?, ?, ?,?)";
            Object[] params = {shipping.getUserId(), shipping.getReceiverName(), shipping.getReceiverPhone(), shipping.getReceiverMobile(),
                    shipping.getReceiverProvince(), shipping.getReceiverCity(), shipping.getReceiverAddress(), shipping.getReceiverZip(), shipping.getCreateTime(), shipping.getUpdateTime()};

            // 执行
            result = BaseDao.executeUpdate(connection, sql, params, pstm);

            BaseDao.closeResource(null, pstm, rs);
        }
        return result;
    }

    @Override
    public int deleteShipping(Connection connection, Integer shippingId) throws SQLException {
        return 0;
    }

    @Override
    public int updateShipping(Connection connection, Shipping shipping) throws SQLException {
        return 0;
    }

    @Override
    public Shipping selectShipping(Connection connection, Integer shippingId) throws SQLException {
        return null;
    }
}
